// pages/drugs_recommend/drugs_recommend.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    drugsArr:[
      { img: "../images/active_01.png", title: "六味地黄丸", effect: "补血补气、降血压、乱七八糟", pic:"1980"},
      { img: "../images/active_01.png", title: "六味地黄丸", effect: "补血补气、降血压、乱七八糟", pic: "1980" }  ,
      { img: "../images/active_01.png", title: "六味地黄丸", effect: "补血补气、降血压、乱七八糟", pic: "1980" }    
    ],
    chooseScreen:[
      { title: "滋补调养" }, { title: "滋补调养" }, { title: "滋补调养" }, { title: "滋补调养" }, { title: "滋补调养" }
    ],
    hidden:true,
    hidden2:true,
    hidden3:true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
  },
  chooseDrugs:function(e){
    console.log(e)
    var that = this
    var drugsArr = that.data.drugsArr
    drugsArr[e.currentTarget.dataset.index].checked = !drugsArr[e.currentTarget.dataset.index].checked
    that.setData({
      drugsArr: drugsArr
    })
  },
  //展示筛选
  show:function(){
    this.setData({
      hidden:false,
      hidden2:true,
      hidden3:true
    })
  },
  show2:function(){
    this.setData({
      hidden: true,
      hidden2: false,
      hidden3: true
    })
  },
  show3:function(){
    this.setData({
      hidden: true,
      hidden2: true,
      hidden3: false
    })
  },
  //选择
  chooseScreen:function(e){
    var that = this
    var chooseScreen = that.data.chooseScreen
    chooseScreen[e.currentTarget.dataset.index].checked = !chooseScreen[e.currentTarget.dataset.index].checked
    that.setData({
      chooseScreen: chooseScreen
    })    
  },
  //关闭筛选
  close:function(){
    this.setData({
      hidden: true,
      hidden2: true,
      hidden3: true
    })
  },
  //推荐
  tuijian:function(){
    var that = this
    var drugsArr = that.data.drugsArr
    console.log(drugsArr)
  
    var arr = []
    for (var i = 0, len = drugsArr.length ; i < len ;i++){
      var obj = {}
      if (drugsArr[i].checked){
        obj.img = drugsArr[i].img
        obj.name = drugsArr[i].title
        arr.push(obj)
      }
    }
    wx.setStorageSync('imgArr', arr)
    setTimeout(function(){
      wx.navigateBack({
        delta:1
      })
    },)
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})